var CardSprite = cc.Sprite.extend({
    type:null,
    num:null,
    _choosed : false,
    /* @param {String} background
    * @param {String} foreground
    * @param {String} card name
    * @param {Number} (optional) card num
    */
    initWithFileNames:function(background,foreground,cardName,cardNum){
        this.initWithFile(background);
        this.setAnchorPoint(cc.p(0,0));
        this._foregroundSprite = cc.Sprite.create(foreground);
        this._foregroundSprite.setAnchorPoint(cc.p(0,0));
        this._foregroundSprite.setPosition(cc.p(8,38));
        this.addChild(this._foregroundSprite);
        this._nameSprite = cc.Sprite.create(cardName);
        this._nameSprite.setAnchorPoint(cc.p(0,0));
        this._nameSprite.setPosition(cc.p(0,12));
        this.addChild(this._nameSprite);
        if(cardNum){
            this._numSprite = cc.Sprite.create(s_CardNum,cc.rect(0,16*(cardNum-1),16,16));
            this._numSprite.setPosition(cc.p(8,168));
            this._numSprite.setAnchorPoint(cc.p(0,0));
            this.addChild(this._numSprite);
        }
    },
    disable:function(){
        this._foregroundSprite.setOpacity(200);
        this._nameSprite.setOpacity(200);
        if(this._numSprite)
            this._numSprite.setOpacity(200);
        this.setOpacity(200);
    },
    enable:function(){
        this._foregroundSprite.setOpacity(255);
        this._nameSprite.setOpacity(255);
        if(this._numSprite)
            this._numSprite.setOpacity(255);
        this.setOpacity(255);
    },
    isSpecialCard:function(){
        return this._name!=null && this._name != "attack";
    },
    isChoosed:function(){
        return this._choosed;
    },
    touchRect : function(){
        var rect = this.getBoundingBox();
        rect.origin = this.getParent().convertToWorldSpace(this.getPosition());
        return rect;
    },
    initWithCardName:function(name,cardNum){
        this.type = name;
        this.num = cardNum;
        this.initWithFileNames.apply(this,g_ClientConfig.cards[name].imgs.concat(cardNum));
    },
    toggleCard:function(){
        if(this._choosed)
        {
            var act = cc.MoveBy.create(0.1,cc.p(0,-35));
            this._choosed = false;
        }
        else
        {
            var act = cc.MoveBy.create(0.1,cc.p(0,35));
            this._choosed = true;
        }
        this.runAction(act);
    },
    //添加点击事件
    onEnter: function(){
        cc.Director.getInstance().getTouchDispatcher().addStandardDelegate(this, 0);
        this._super();
    },
    onExit:function(){
        cc.Director.getInstance().getTouchDispatcher().removeDelegate(this);
        this._super();
    },
});